package com.kingbi.system.roleFunction.dao;

import java.util.ArrayList;

import com.kingbi.system.roleFunction.model.RoleFunctionModel;

public class RoleFunctionQuery
{
    StringBuilder search_query_bud;

    StringBuilder search_count_bud;

    StringBuilder temp_bud;

    Object[] params;

    ArrayList paramList;

    public RoleFunctionQuery()
    {
        super();
    }

    public RoleFunctionQuery(StringBuilder search_query_bud, StringBuilder search_count_bud,
            StringBuilder temp_bud)
    {
        super();

    }

    public void doSearchQuery(RoleFunctionModel roleFunctionModel)
    {
        this.search_query_bud = new StringBuilder();
        this.search_count_bud = new StringBuilder();
        search_query_bud
                .append("from com.kingbi.system.roleFunction.model.RoleFunctionModel roleFunction where 1=1");
        search_count_bud
                .append("select count(*) from com.kingbi.system.roleFunction.model.RoleFunctionModel roleFunction where 1=1");
        temp_bud = new StringBuilder();
        paramList = new ArrayList();

        if(roleFunctionModel.getRoleFunID().getRoleCode() != null && !roleFunctionModel.getRoleFunID().getRoleCode().equals("")
                && !roleFunctionModel.getRoleFunID().getRoleCode().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleFunID.roleCode=?");
            paramList.add(roleFunctionModel.getRoleFunID().getRoleCode().trim());
        }
        if(roleFunctionModel.getRoleFunID().getFunctionCode() != null
                && !roleFunctionModel.getRoleFunID().getFunctionCode().equals("")
                && !roleFunctionModel.getRoleFunID().getFunctionCode().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleFunID.functionCode=?");
            paramList.add(roleFunctionModel.getRoleFunID().getFunctionCode().trim());
        }
        if(roleFunctionModel.getRoleRight() != null && !roleFunctionModel.getRoleRight().equals("")
                && !roleFunctionModel.getRoleRight().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleRight=?");
            paramList.add(roleFunctionModel.getRoleRight().trim());
        }

        if(paramList != null && paramList.size() > 0)
        {
            params = new Object[paramList.size()];
            for (int i = 0; i < paramList.size(); i++)
            {
                params[i] = paramList.get(i);
            }
        }

        if(temp_bud != null && temp_bud.length() > 0)
        {
            search_query_bud.append(temp_bud.toString());
            search_count_bud.append(temp_bud.toString());
        }

    }

    public void doListRoleFun(RoleFunctionModel roleFunctionModel)
    {
        this.search_query_bud = new StringBuilder();
        this.search_count_bud = new StringBuilder();
        search_query_bud
                .append("from com.kingbi.system.roleFunction.model.RoleFunctionModel roleFunction,com.kingbi.system.function.model.FunctionModel fun "
                        + " where roleFunction.roleFunID.functionCode=fun.funcCode");

        temp_bud = new StringBuilder();
        paramList = new ArrayList();

        if(roleFunctionModel.getRoleFunID().getRoleCode() != null && !roleFunctionModel.getRoleFunID().getRoleCode().equals("")
                && !roleFunctionModel.getRoleFunID().getRoleCode().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleFunID.roleCode=?");
            paramList.add(roleFunctionModel.getRoleFunID().getRoleCode().trim());
        }
        if(roleFunctionModel.getRoleFunID().getFunctionCode() != null
                && !roleFunctionModel.getRoleFunID().getFunctionCode().equals("")
                && !roleFunctionModel.getRoleFunID().getFunctionCode().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleFunID.functionCode=?");
            paramList.add(roleFunctionModel.getRoleFunID().getFunctionCode().trim());
        }
        if(roleFunctionModel.getRoleRight() != null && !roleFunctionModel.getRoleRight().equals("")
                && !roleFunctionModel.getRoleRight().equals("null"))
        {
            temp_bud.append(" and roleFunction.roleRight=?");
            paramList.add(roleFunctionModel.getRoleRight().trim());
        }

        if(paramList != null && paramList.size() > 0)
        {
            params = new Object[paramList.size()];
            for (int i = 0; i < paramList.size(); i++)
            {
                params[i] = paramList.get(i);
            }
        }

        if(temp_bud != null && temp_bud.length() > 0)
        {
            search_query_bud.append(temp_bud.toString());
            search_count_bud.append(temp_bud.toString());
        }

    }

    public StringBuilder getSearch_query_bud()
    {
        return search_query_bud;
    }

    public void setSearch_query_bud(StringBuilder search_query_bud)
    {
        this.search_query_bud = search_query_bud;
    }

    public StringBuilder getSearch_count_bud()
    {
        return search_count_bud;
    }

    public void setSearch_count_bud(StringBuilder search_count_bud)
    {
        this.search_count_bud = search_count_bud;
    }

    public StringBuilder getTemp_bud()
    {
        return temp_bud;
    }

    public void setTemp_bud(StringBuilder temp_bud)
    {
        this.temp_bud = temp_bud;
    }

    public Object[] getParams()
    {
        return params;
    }

    public void setParams(Object[] params)
    {
        this.params = params;
    }

}